Dylan (programming Language)
   HOME

TheInfoList



OR:

Dylan is a multi-paradigm
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
that includes support for
functional Functional may refer to: * Movements in architecture: ** Functionalism (architecture) ** Form follows function * Functional group, combination of atoms within molecules * Medical conditions without currently visible organic basis: ** Functional sy ...
and
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
(OOP), and is
dynamic Dynamics (from Greek δυναμικός ''dynamikos'' "powerful", from δύναμις ''dynamis'' "power") or dynamic may refer to: Physics and engineering * Dynamics (mechanics) ** Aerodynamics, the study of the motion of air ** Analytical dynam ...
and
reflective Reflection is the change in direction of a wavefront at an interface between two different media so that the wavefront returns into the medium from which it originated. Common examples include the reflection of light, sound and water waves. The ' ...
while providing a programming model designed to support generating efficient machine code, including fine-grained control over dynamic and static behaviors. It was created in the early 1990s by a group led by
Apple Computer Apple Inc. is an American multinational technology company headquartered in Cupertino, California, United States. Apple is the largest technology company by revenue (totaling in 2021) and, as of June 2022, is the world's biggest company b ...
. Dylan derives from
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
and
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
and adds an integrated object system derived from the
Common Lisp Object System The Common Lisp Object System (CLOS) is the facility for object-oriented programming which is part of ANSI Common Lisp. CLOS is a powerful dynamic object system which differs radically from the OOP facilities found in more static languages such as ...
(CLOS). In Dylan, all values (including numbers, characters, functions, and classes) are
first-class object In programming language design, a first-class citizen (also type, object, entity, or value) in a given programming language is an entity which supports all the operations generally available to other entities. These operations typically include ...
s. Dylan supports
multiple inheritance Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit features from more than one parent object or parent class. It is distinct from single inheritance, where an object or ...
, polymorphism,
multiple dispatch Multiple dispatch or multimethods is a feature of some programming languages in which a function or method can be dynamically dispatched based on the run-time (dynamic) type or, in the more general case, some other attribute of more than one of ...
,
keyword argument In computer programming, named parameters, named argument or keyword arguments refer to a computer language's support for function calls that clearly state the name of each parameter within the function call. Overview A function call using name ...
s, object introspection,
pattern A pattern is a regularity in the world, in human-made design, or in abstract ideas. As such, the elements of a pattern repeat in a predictable manner. A geometric pattern is a kind of pattern formed of geometric shapes and typically repeated l ...
-based syntax extension macros, and many other advanced features. Programs can express fine-grained control over dynamism, admitting programs that occupy a continuum between dynamic and static programming and supporting evolutionary development (allowing for rapid prototyping followed by incremental refinement and optimization). Dylan's main design goal is to be a dynamic language well-suited for developing
commercial software Commercial software, or seldom payware, is a computer software that is produced for sale or that serves commercial purposes. Commercial software can be proprietary software or free and open-source software. Background and challenge While soft ...
. Dylan attempts to address potential performance issues by introducing "natural" limits to the full flexibility of
Lisp A lisp is a speech impairment in which a person misarticulates sibilants (, , , , , , , ). These misarticulations often result in unclear speech. Types * A frontal lisp occurs when the tongue is placed anterior to the target. Interdental lisping ...
systems, allowing the
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
to clearly understand compilable units, such as
libraries A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vir ...
. Dylan derives much of its semantics from Scheme and other Lisps; some Dylan implementations were initially built within extant Lisp systems. However, Dylan has an
ALGOL ALGOL (; short for "Algorithmic Language") is a family of imperative computer programming languages originally developed in 1958. ALGOL heavily influenced many other languages and was the standard method for algorithm description used by the ...
-like syntax instead of a Lisp-like prefix syntax.


History

Dylan was created in the early 1990s by a group led by
Apple Computer Apple Inc. is an American multinational technology company headquartered in Cupertino, California, United States. Apple is the largest technology company by revenue (totaling in 2021) and, as of June 2022, is the world's biggest company b ...
. At one time in its development, it was intended for use with the
Apple Newton The Newton is a series of personal digital assistants (PDAs) developed and marketed by Apple Computer, Inc. An early device in the PDA category (the Newton originated the term), it was the first to feature handwriting recognition. Apple started ...
computer, but the Dylan implementation did not reach sufficient maturity in time, and Newton instead used a mix of C and the
NewtonScript NewtonScript is a prototype-based programming language created to write programs for the Newton platform. It is heavily influenced by the Self programming language, but modified to be more suited to needs of mobile and embedded devices. Histo ...
developed by Walter Smith. Apple ended their Dylan development effort in 1995, though they made a "technology release" version available (Apple Dylan TR1) that included an advanced
integrated development environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools a ...
(IDE). Two other groups contributed to the design of the language and developed implementations:
Harlequin Harlequin (; it, Arlecchino ; lmo, Arlechin, Bergamasque dialect, Bergamasque pronunciation ) is the best-known of the ''zanni'' or comic servant characters from the Italian language, Italian ''commedia dell'arte'', associated with the city o ...
released a commercial IDE for
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
and
Carnegie Mellon University Carnegie Mellon University (CMU) is a private research university in Pittsburgh, Pennsylvania. One of its predecessors was established in 1900 by Andrew Carnegie as the Carnegie Technical Schools; it became the Carnegie Institute of Technology ...
released an
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
compiler for
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
systems called Gwydion Dylan. Both of these implementations are now open source. The Harlequin implementation is now named Open Dylan and is maintained by a group of volunteers, the Dylan Hackers. The Dylan language was code-named Ralph. James Joaquin chose the name Dylan for "DYnamic LANguage."


Syntax

Many of Dylan's syntax features come from its Lisp heritage. Originally, Dylan used a Lisp-like prefix syntax, which was based on
s-expression In computer programming, an S-expression (or symbolic expression, abbreviated as sexpr or sexp) is an expression in a like-named notation for nested list (tree-structured) data. S-expressions were invented for and popularized by the programming la ...
s. By the time the language design was completed, the syntax was changed to an ALGOL-like syntax, with the expectation that it would be more familiar to a wider audience of programmers. The syntax was designed by Michael Kahl. It is described in great detail in the Dylan Reference Manual.


Lexical syntax

Dylan is not
case sensitive Case or CASE may refer to: Containers * Case (goods), a package of related merchandise * Cartridge case or casing, a firearm cartridge component * Bookcase, a piece of furniture used to store books * Briefcase or attaché case, a narrow box to ...
. Dylan's
lexical syntax In computer science, lexical analysis, lexing or tokenization is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of ''lexical tokens'' ( strings with an assigned and thus identified ...
allows the use of a naming convention where hyphen (minus) signs are used to connect the parts of multiple-word identifiers (sometimes called " lisp-case" or "
kebab case Letter case is the distinction between the Letter (alphabet), letters that are in larger uppercase or capitals (or more formally ''majuscule'') and smaller lowercase (or more formally ''minuscule'') in the written representation of certain lang ...
"). This convention is common in Lisp languages but cannot be used in programming languages that treat any hyphen-minus that is not part of a numeric literal as a single
lexical token In computer science, lexical analysis, lexing or tokenization is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of ''lexical tokens'' ( strings with an assigned and thus identified ...
, even when not surrounded by
whitespace character In computer programming, whitespace is any character or series of characters that represent horizontal or vertical space in typography. When rendered, a whitespace character does not correspond to a visible mark, but typically does occupy an area ...
s. Besides
alphanumeric Alphanumericals or alphanumeric characters are a combination of alphabetical and numerical characters. More specifically, they are the collection of Latin letters and Arabic digits. An alphanumeric code is an identifier made of alphanumeric ch ...
characters and hyphen-minus signs, Dylan allows certain non-alphanumerical characters as part of identifiers. Identifiers may not consist of these non-alphanumeric characters or of numeric characters alone. If there is any ambiguity, whitespace is used.


Example code

A simple class with several slots: define class () slot point-x :: , required-init-keyword: x:; slot point-y :: , required-init-keyword: y:; end class ; By convention, classes are named with less-than and greater-than signs used as
angle bracket A bracket is either of two tall fore- or back-facing punctuation marks commonly used to isolate a segment of text or data from its surroundings. Typically deployed in symmetric pairs, an individual bracket may be identified as a 'left' or 'r ...
s, e.g. the class named <point> in the code example. In end class <point> both class and <point> are optional. This is true for all end clauses. For example, you may write end if or just end to terminate an if statement. To make an instance of <point>: make(, x: 100, y: 200) The same class, rewritten in the most minimal way possible: define class () slot point-x; slot point-y; end; The slots are now both typed as <object>. The slots must be initialized manually: let p = make(); point-x(p) := 100; // or p.point-x := 100; point-y(p) := 200; // or p.point-y := 200; By convention, constant names begin with "$": define constant $pi :: = 3.1415927d0; A factorial function: define function factorial (n :: ) => (n! :: ) case n < 0 => error("Can't take factorial of negative integer: %d\n", n); n = 0 => 1; otherwise => n * factorial(n - 1); end end; Here, n! and <integer> are just normal identifiers. There is no explicit
return statement In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is sav ...
. The result of a method or function is the last expression evaluated. It is a common style to leave off the semicolon after an expression in return position.


Modules vs. namespace

In many object-oriented languages, classes are the main means of encapsulation and modularity; each class defines a namespace and controls which definitions are externally visible. Further, classes in many languages define an indivisible unit that must be used as a whole. For example, using a String concatenation function requires importing and compiling against all of String. Some languages, including Dylan, also include a separate, explicit namespace or module system that performs encapsulation in a more general way. In Dylan, the concepts of compile-unit and import-unit are separated, and classes have nothing specifically to do with either. A ''library'' defines items that should be compiled and handled together, while a ''module'' defines a namespace. Classes can be placed together in modules, or cut across them, as the programmer wishes. Often the complete definition for a class does not exist in a single module, but is spread across several that are optionally collected together. Different programs can have different definitions of the same class, including only what they need. For example, consider an add-on library for
regex A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or ...
support on String. In some languages, for the functionality to be included in strings, the functionality must be added to the String namespace. As soon as this occurs, the String class becomes larger, and functions that don't need to use regex still must "pay" for it in increased library size. For this reason, these sorts of add-ons are typically placed in their own namespaces and objects. The downside to this approach is that the new functions are no longer a ''part of'' String; instead, it is isolated in its own set of functions that must be called separately. Instead of myString.parseWith(myPattern), which would be the natural organization from an OO viewpoint, something like myPattern.parseString(myString) is used, which effectively reverses the ordering. Under Dylan, many interfaces can be defined for the same code, for instance the String concatenation method could be placed in both the String interface, and the "concat" interface which collects together all of the different concatenation functions from various classes. This is more commonly used in math libraries, where functions tend to be applicable to widely differing object types. A more practical use of the interface construct is to build public and private versions of a module, something that other languages include as a ''bolt on'' feature that invariably causes problems and adds syntax. Under Dylan, every function call can be simply places in the "Private" or "Development" interface, and collect up publicly accessible functions in Public. Under
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
or
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
the visibility of an object is defined in the code, meaning that to support a similar change, a programmer would be forced to rewrite the definitions fully, and could not have two versions at the same time.


Classes

Classes in Dylan describe slots (data members, fields, ivars, etc.) of objects in a fashion similar to most OO languages. All access to slots is via methods, as in
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
. Default getter and setter methods are automatically generated based on the slot names. In contrast with most other OO languages, other methods applicable to the class are often defined outside of the class, and thus class definitions in Dylan typically include the definition of the storage only. For instance: define class () slot title :: = "untitled", init-keyword: title:; slot position :: , required-init-keyword: position:; end class; In this example, the class "<window>" is defined. The <class name> syntax is convention only, to make the class names stand out—the angle brackets are merely part of the class name. In contrast, in some languages the convention is to capitalize the first letter of the class name or to prefix the name with a ''C'' or ''T'' (for example). <window> inherits from a single class, <view>, and contains two slots, title holding a string for the window title, and position holding an X-Y point for a corner of the window. In this example, the title has been given a default value, while the position has not. The optional ''init-keyword'' syntax allows the programmer to specify the initial value of the slot when instantiating an object of the class. In languages such as C++ or Java, the class would also define its interface. In this case the definition above has no explicit instructions, so in both languages access to the slots and methods is considered protected, meaning they can be used only by subclasses. To allow unrelated code to use the window instances, they must be declared public. In Dylan, these sorts of visibility rules are not considered part of the code, but of the module/interface system. This adds considerable flexibility. For instance, one interface used during early development could declare everything public, whereas one used in testing and deployment could limit this. With C++ or Java these changes would require changes to the source code, so people won't do it, whereas in Dylan this is a fully unrelated concept. Although this example does not use it, Dylan also supports
multiple inheritance Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit features from more than one parent object or parent class. It is distinct from single inheritance, where an object or ...
.


Methods and generic functions

In Dylan, methods are not intrinsically associated with any specific class; methods can be thought of as existing outside of classes. Like CLOS, Dylan is based on
multiple dispatch Multiple dispatch or multimethods is a feature of some programming languages in which a function or method can be dynamically dispatched based on the run-time (dynamic) type or, in the more general case, some other attribute of more than one of ...
(multimethods), where the specific method to be called is chosen based on the types of all its arguments. The method need not be known at compile time, the understanding being that the required function may be available, or not, based on a user's preferences. Under Java the same methods would be isolated in a specific class. To use that functionality the programmer is forced to ''import'' that class and refer to it explicitly to call the method. If that class is unavailable, or unknown at compile time, the application simply won't compile. In Dylan, code is isolated from storage in ''functions''. Many classes have methods that call their own functions, thereby looking and feeling like most other OO languages. However code may also be located in ''generic functions'', meaning they are not attached to a specific class, and can be called natively by anyone. Linking a specific generic function to a method in a class is accomplished thusly: define method turn-blue (w :: ) w.color := $blue; end method; This definition is similar to those in other languages, and would likely be encapsulated within the <window> class. Note the := setter call, which is
syntactic sugar In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for human use: things can be expressed more clearly, more concisely, or in an ...
for color-setter($blue, w). The utility of generic methods comes into its own when you consider more "generic" examples. For instance, one common function in most languages is the to-string, which returns some
human-readable A human-readable medium or human-readable format is any encoding of data or information that can be naturally read by humans. In computing, ''human-readable'' data is often encoded as ASCII or Unicode text, rather than as binary data. In most c ...
form for the object. For instance, a window might return its title and its position in parens, while a string would return itself. In Dylan these methods could all be collected into a single module called "to-string", thereby removing this code from the definition of the class itself. If a specific object did not support a to-string, it could be easily added in the to-string module.


Extensibility

This whole concept might strike some readers as very odd. The code to handle to-string for a window isn't defined in <window>? This might not make any sense until you consider how Dylan handles the call of the to-string. In most languages when the program is compiled the to-string for <window> is looked up and replaced with a pointer (more or less) to the method. In Dylan this occurs when the program is first run; the runtime builds a table of method-name/parameters details and looks up methods dynamically via this table. That means that a function for a specific method can be located anywhere, not just in the compile-time unit. In the end the programmer is given considerable flexibility in terms of where to place their code, collecting it along class lines where appropriate, and functional lines where it's not. The implication here is that a programmer can add functionality to existing classes by defining functions in a separate file. For instance, you might wish to add spell checking to all <string>s, which in C++ or Java would require access to the source code of the string class—and such basic classes are rarely given out in source form. In Dylan (and other "extensible languages") the spell checking method could be added in the spell-check module, defining all of the classes on which it can be applied via the define method construct. In this case the actual functionality might be defined in a single generic function, which takes a string and returns the errors. When the spell-check module is compiled into your program, all strings (and other objects) will get the added functionality.


Apple Dylan

Apple Dylan is the implementation of Dylan produced by
Apple Computer Apple Inc. is an American multinational technology company headquartered in Cupertino, California, United States. Apple is the largest technology company by revenue (totaling in 2021) and, as of June 2022, is the world's biggest company b ...
. It was originally developed for the
Apple Newton The Newton is a series of personal digital assistants (PDAs) developed and marketed by Apple Computer, Inc. An early device in the PDA category (the Newton originated the term), it was the first to feature handwriting recognition. Apple started ...
product.


References


External links

*, Open Dylan – hosts open source, optimizing Dylan compiler targeting Unix/Linux, macOS, Microsoft Windows
Overview of the languageAn Introduction to DylanApple Dylan TR1The Marlais Dylan Interpreter
– An implementation of a subset of Dylan, suitable for bootstrapping a compiler * {{Authority control Cross-platform software Extensible syntax programming languages Lisp programming language family Programming languages created in 1992